package com.crazymaker.springcloud.message.start;


import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.crazymaker.springcloud.standard.config.TokenFeignConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@EnableAutoConfiguration(exclude = {
        //排除db的自动配置
//        DataSourceAutoConfiguration.class,
//        DataSourceTransactionManagerAutoConfiguration.class,
//        HibernateJpaAutoConfiguration.class,
        //排除redis的自动配置
//        RedisAutoConfiguration.class,
//        RedisRepositoriesAutoConfiguration.class,

        //排除 druid
        DruidDataSourceAutoConfigure.class,
        //排除 spring  Security
        SecurityAutoConfiguration.class,
        ManagementWebSecurityAutoConfiguration.class
})

@SpringBootApplication(scanBasePackages =
        {
                "com.crazymaker.springcloud.message",
                "com.crazymaker.springcloud.user",
                "com.crazymaker.springcloud.base",
                "com.crazymaker.springcloud.seckill.remote.fallback",
                "com.crazymaker.springcloud.standard"
        })
@EnableScheduling
@EnableJpaRepositories(basePackages = {
        "com.crazymaker.springcloud.message.dao",
        "com.crazymaker.springcloud.user.*.dao",
        "com.crazymaker.springcloud.base.dao"
})
@EntityScan(basePackages = {

        "com.crazymaker.springcloud.user.*.dao.po",
        "com.crazymaker.springcloud.base.dao.po",
        "com.crazymaker.springcloud.message.dao.po",
        "com.crazymaker.springcloud.standard.*.dao.po"


})
@EnableTransactionManagement(proxyTargetClass = true)

@EnableFeignClients(basePackages = "com.crazymaker.springcloud.tunnel.remote.client",
        defaultConfiguration = {TokenFeignConfiguration.class})
@EnableSwagger2
@EnableHystrix
@EnableCircuitBreaker

@Slf4j
public class MessageDispatchApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        setRegisterErrorPageFilter(false);
        return application.sources(MessageDispatchApplication.class);
    }


    public static void main(String[] args) {

        ConfigurableApplicationContext applicationContext = SpringApplication.run(MessageDispatchApplication.class, args);

        Environment env = applicationContext.getEnvironment();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
//        String ip = env.getProperty("eureka.instance.ip-address");
        String ip = "127.0.0.1";

        log.info("\n----------------------------------------------------------\n\t" +
                "UAA 推送中台 push-provider is running! Access URLs:\n\t" +
                "Local: \t\thttp://" + ip + ":" + port + path + "/\n\t" +
                "swagger-ui: \thttp://" + ip + ":" + port + path + "/swagger-ui.html\n\t" +
                "actuator: \thttp://" + ip + ":" + port + path + "/actuator/info\n\t" +
                "----------------------------------------------------------");
    }
}
